import { Action, ActionType } from '@/types/event';
import { panelActionMap } from './panel';
import { stageActionMap } from './stage';

const ActionDispatcher: Record<ActionType, any> = {
  panel: panelActionMap,
  stage: stageActionMap,
};

/**
 * 派发动作执行
 * @param actions
 */
export const dispatchActions = (actions: Action[]) => {
  actions.forEach((o) => {
    const { type, target, method, value } = o;
    if (type === 'panel') {
      ActionDispatcher.panel[method](target, value);
      return;
    }
    if (type === 'stage') {
      ActionDispatcher.stage[method](target, value);
    }
  });
};
